<template>
  <vue-scroll class="page-building">
    <div class="page-header card-base header-accent">
      <h1>
        <span>会议室列表</span>
        <div class="mt-10">
          <el-button type="primary" @click="createClick">
            <i class="mdi mdi-plus"></i> 新增
          </el-button>
        </div>
      </h1>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">
          <i class="mdi mdi-home-outline"></i>
        </el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/ecommerce' }">会议室</el-breadcrumb-item>
        <el-breadcrumb-item>列表</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-row>
      <el-col>
        <div class="table-box card-base card-shadow--medium">
          <el-table
            :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
            style="width: 100%"
          >
            <el-table-column prop="name" label="名称" align="left" sortable min-width="10%">
              <template slot-scope="scope">
                <el-button
                  title="查看详情"
                  @click="viewClick(scope.row.id)"
                  type="text"
                  size="small"
                >{{scope.row.name}}</el-button>
              </template>
            </el-table-column>
            <el-table-column label="场所" header-align="center" align="center" min-width="10%">
              <template slot-scope="scope">{{scope.row.building && scope.row.building.name}}</template>
            </el-table-column>
            <el-table-column label="设施" header-align="center" align="center" min-width="15%">
              <template
                slot-scope="scope"
              >{{scope.row.meetingroomfacilities.map(x=>x.facility.name).join()}}</template>
            </el-table-column>
            <el-table-column
              prop="chargeperhour"
              label="费用/时"
              header-align="center"
              align="center"
              min-width="8%"
            ></el-table-column>
            <el-table-column
              prop="capacity"
              label="容量人数"
              sortable
              header-align="center"
              align="center"
              min-width="8%"
            ></el-table-column>

            <el-table-column label="开放时间" header-align="center" align="center" min-width="8%">
              <template slot-scope="scope">
                <span>{{scope.row.opentime}} - {{scope.row.closetime}}</span>
              </template>
            </el-table-column>

            <el-table-column
              fixed="right"
              header-align="center"
              align="center"
              label="操作"
              width="140"
            >
              <template slot-scope="scope">
                <el-button @click="editClick(scope.row.id)" type="text" size="small">修改</el-button>
                <el-button @click="deleteClick(scope.row.id)" type="text" size="small">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            class="paging"
            background
            :current-page="currentPage"
            layout="prev, pager, next"
            :total="total"
            @current-change="currentChange"
          ></el-pagination>
        </div>
      </el-col>
    </el-row>
    <meetingroomdialog
      :dialogvisible.sync="dialogvisible"
      :displaytype="displaytype"
      :meetingroomid="meetingroomid"
      :totalnumber="total"
      @success="formSubmitSuccess"
    ></meetingroomdialog>
  </vue-scroll>
</template>

<script>
import axios from "axios";
import store from "../../../store";
import meetingroomdialog from "../../../components/MeetingRoomDialog";

export default {
  name: "meetingroom",

  components: { meetingroomdialog },

  beforeRouteEnter(to, from, next) {
    next();
  },

  data() {
    var self = this;
    return {
      tableData: [],
      total: 0,
      pagesize: 10,
      currentPage: 1,
      meetingroomid: 0,
      displaytype: "",
      dialogvisible: false
    };
  },
  methods: {
    currentChange: function(currentPage) {
      this.currentPage = currentPage;
    },
    deleteClick(id) {
      var self = this;
      this.$confirm(
        "此操作会永久删除此会议室和其相关的设施等，确定继续?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          center: true
        }
      )
        .then(() => {
          axios
            .post("/api/meetingroom/Remove/" + id)
            .then(response => {
              this.tableData = response.data.data;
              this.total = response.data.data.length;
              this.currentPage = 1;
              this.$message({
                type: "success",
                message: "删除成功"
              });
            })
            .catch(ex => {
              console.log(ex);
            });
        })
        .catch(ex => {
          console.log(ex);
        });
    },
    viewClick(id) {
      this.meetingroomid = id;
      this.displaytype = "view";
      this.dialogvisible = true;
    },
    createClick() {
      this.meetingroomid = 0;
      this.displaytype = "add";
      this.dialogvisible = true;
    },
    editClick(id) {
      this.meetingroomid = id;
      this.displaytype = "edit";
      this.dialogvisible = true;
    },
    formSubmitSuccess(data) {
      //console.log(data);
      this.tableData = data;
      this.total = data.length;
      this.currentPage = 1;
      //this.dialogVisible = false;
      this.$message({
        type: "success",
        message: this.displaytype == "add" ? "新增成功" : "修改成功"
      });
    }
  },
  created() {
    axios.get("/api/meetingroom").then(response => {
      this.tableData = response.data.data;
      this.total = response.data.data.length;
      this.currentPage = 1;
    });
  },
  watch: {
    $route(to, from) {
      // react to route changes...
    }
  }
};
</script>

<style lang="scss" scoped>
@import "../../../assets/scss/_variables";
</style>

<style lang="scss">
.page-building {
  .page-header {
    margin-bottom: 8px;
  }
  .hrline {
    height: 3px;
    margin-top: -35px;
    background-color: #d7195d;
    border: none;
  }
  .input-width {
    width: 350px;
  }

  .line {
    text-align: center;
    line-height: 37px;
  }

  .error {
    color: #d7195d;
    font-size: 12px;
    padding-left: 10px;
    line-height: 12px;
    padding-top: 4px;
  }
  h1 {
    button {
      float: right;
      padding: 10px 25px;
      background: rgba(255, 255, 255, 0.2);
      text-transform: uppercase;
      border: none;
      outline: none;
      cursor: pointer;
      color: white;
      opacity: 0.8;
      font-family: inherit;

      i {
        position: relative;
        top: 1px;
      }

      &:hover {
        opacity: 1;
      }
    }
  }
  .table-box {
    overflow: auto;
  }

  .uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .uploader .el-upload:hover {
    border-color: #409eff;
  }
  .uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 78px;
    height: 78px;
    line-height: 78px;
    text-align: center;
  }
  .mrpic {
    width: 78px;
    height: 78px;
    display: block;
  }
}

@media (max-width: 768px) {
  .page-building {
    .vb-content {
      padding: 0 5px !important;
      margin: -5px;
      width: calc(100% + 10px) !important;
    }
  }
}
</style>


